<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人简历信息</title>
    <link rel="stylesheet" href="../../plugins/element-ui/theme-chalk/index.css"/>
    <script src="../../js/vue.js" charset="utf-8"></script>
    <script src="../../plugins/element-ui/index.js" charset="utf-8"></script>
    <!-- 引入axios -->
    <script src="../../plugins/axios.min.js"></script>

    <script src="../../js/request.js"></script>
    <script src="../../js/personalResumes.js"></script>

    <style name="table">
        .el-table .warning-row {
            background: oldlace;
        }

        .el-table .success-row {
            background: #f0f9eb;
        }
    </style>
</head>
<body>

<div id="container">
    <!--功能按钮-->
    <el-row>
        <el-button type="primary" plain @click="addDialogFormVisible = true">新增</el-button>
    </el-row>

    <!--新建框表单-->
    <el-dialog title="简历信息" :visible.sync="addDialogFormVisible">
        <el-form :model="resume">
            <el-form-item label="姓名" :label-width="formLabelWidth">
                <el-input v-model="resume.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="应聘岗位" :label-width="formLabelWidth">
                <el-input v-model="resume.position" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="毕业院校" :label-width="formLabelWidth">
                <el-input v-model="resume.graduation" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="技术栈" :label-width="formLabelWidth">
                <el-input v-model="resume.technologyStack" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="addDialogFormVisible = false">取消</el-button>
            <el-button type="primary" @click="add">保存</el-button>
        </div>
    </el-dialog>

    <!--table表格 -->
    <template>
        <el-table
                :data="tableData"
                style="width: 100%"
                :row-class-name="tableRowClassName">
            <el-table-column
                    prop="position"
                    label="岗位"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="姓名"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="graduation"
                    label="毕业院校"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="technologyStack"
                    label="技术栈"
                    align="center">
            </el-table-column>
            <el-table-column
                    align="center"
                    label="操作">
                <!--修改对话框表单-->
                <template slot-scope="scope">
                        <el-button type="primary"  @click="Update(scope.row)">修改</el-button>
                        <el-button type="danger"  @click="Delete(scope.row)">删除</el-button>
                    <el-dialog title="简历信息" :visible.sync="updateDialogFormVisible">
                        <el-form :model="resume">
                            <el-form-item label="应聘岗位" :label-width="formLabelWidth">
                                <el-input v-model="resume.position" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="毕业院校" :label-width="formLabelWidth">
                                <el-input v-model="resume.graduation" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="技术栈" :label-width="formLabelWidth">
                                <el-input v-model="resume.technologyStack" autocomplete="off"></el-input>
                            </el-form-item>
                        </el-form>
                        <div slot="footer" class="dialog-footer">
                            <el-button @click="updateDialogFormVisible = false">取消</el-button>
                            <el-button type="primary" @click="exit">修改</el-button>
                        </div>
                    </el-dialog>
                </template>
            </el-table-column>
        </el-table>
    </template>

   <!--分页  -->
    <div class="block">
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[10, 20, 50]"
                :page-size="10"
                layout="total, sizes, prev, pager, next, jumper"
                :total="100">
        </el-pagination>
    </div>

</div>

<script>
    new Vue({
        el:"#container",
        methods: {
            //使不同行颜色不同
            tableRowClassName({row, rowIndex}) {
                if (rowIndex === 1) {
                    return 'warning-row';
                } else if (rowIndex === 3) {
                    return 'success-row';
                }
                return '';
            },

            selectAll(){
                list(this.resume).then(res => {
                    if (String(res.code) === '1') {
                        this.tableData=res.data;
                    } else {
                        this.$message.error(res.msg || '查询失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },
            //通过简历
            add(){
                addResume(this.resume).then(res => {
                    if (String(res.code) === '1') {
                        this.$message.success('添加成功！');
                        this.addDialogFormVisible = false;
                        this.selectAll();
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },

            //删除
            Delete(row){
                this.resume.position = row.position;
                this.resume.graduation= row.graduation;
                this.resume.technologyStack = row.technologyStack
                // 弹出确认提示框
                this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    deleteResume(this.resume).then(res=> {
                        if (String(res.code) === '1') {
                            //重新查询所有，避免刷新
                            this.selectAll();
                            this.$message({
                                message: '删除岗位招聘信息成功！',
                                type: 'success'
                            });
                        } else {
                            this.$message.error({
                                message: '删除岗位招聘信息失败！',
                                type: 'success'
                            });
                        }
                    })
                }).catch(() => {
                    //用户点击取消按钮
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });

            },

           Update(row){
               this.updateDialogFormVisible = true;
               this.resume.position = row.position;
               this.resume.graduation= row.graduation;
               this.resume.technologyStack = row.technologyStack
           },

        exit(){
            editResume(this.resume).then(res => {
                if (String(res.code) === '1') {
                    this.$message.success('修改成功！')
                    this.updateDialogFormVisible = false
                    this.selectAll();
                } else {
                    this.$message.error(res.msg || '操作失败')
                }
            }).catch(err => {
                this.$message.error('请求出错了：' + err)
            })
        },
        },
        created() {
            this.resume.name=localStorage.getItem('user');
            this.selectAll();
        },
        data() {
            return {
                tableData: [],

                //简历模型数据
                resume:{
                   name:"",
                    //应聘岗位
                    position:"",
                    //毕业院校
                    graduation:"",
                    //技术栈
                    technologyStack:"",
                    status:'',

                    employerName:'',
                },

                //默认对话框显示状态和宽度
                addDialogFormVisible: false,
                updateDialogFormVisible: false,
                formLabelWidth: '80px',
            }
        }
    })
</script>
</body>
</html>